package org.zero.onlinesubject.utils;


import org.zero.onlinesubject.common.vo.UserVo;

public class DataDesensitizationUtil {

    public static void desensitizeUserData(UserVo userVo) {
        if(userVo!=null){
            userVo.setPhone(desensitizePhone(userVo.getPhone()));
            userVo.setEmail(desensitizeEmail(userVo.getEmail()));
        }
    }

    private static String desensitizePhone(String phone) {
        // 实现手机号脱敏逻辑，例如隐藏中间四位数字
        if (phone != null && phone.length() == 11) {
            return phone.substring(0, 3) + "****" + phone.substring(7);
        }
        return phone;
    }

    private static String desensitizeEmail(String email) {
        // 实现邮箱脱敏逻辑，例如隐藏@之前的部分
        if (email != null && email.contains("@")) {
            int atIndex = email.indexOf("@");
            return email.substring(0,3)+ "*****" + email.substring(atIndex);
        }
        return email;
    }
}
